package com.lupan.guice.bindings.bindingAnnotations;

import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.name.Names;
import com.lupan.guice.bindings.*;

/**
 * 说明:
 *
 * @author lupan
 * @version 2016/9/27 0027 下午 9:56
 */
public class Main {
    public static void main(String[] args) {
        Injector injector = Guice.createInjector(new AbstractModule() {
            @Override
            protected void configure() {
                bind(CreditCardProcessor.class).annotatedWith(Names.named("processor")).to(PaypalCreditCardProcessor.class);
                bind(TransactionLog.class).annotatedWith(Paypal.class).to(DatabaseTransactionLog.class);
            }
        });

        BillingService2 billingService = injector.getInstance(BillingService2.class);

        billingService.charge();



        Injector injector2 = Guice.createInjector(new AbstractModule() {
            @Override
            protected void configure() {
                bind(CreditCardProcessor.class).annotatedWith(Names.named("processor")).to(PaypalCreditCardProcessor.class);
                bind(TransactionLog.class).annotatedWith(Paypal.class).to(MysqlDatabaseTransactionLog.class);
            }
        });

        BillingService2 billingService2 = injector2.getInstance(BillingService2.class);

        billingService2.charge();

        Injector injector3 = Guice.createInjector(new AbstractModule() {
            @Override
            protected void configure() {
                bind(CreditCardProcessor.class).annotatedWith(Names.named("processor")).to(PaypalCreditCardProcessor.class);
                bind(TransactionLog.class).annotatedWith(Paypal.class).to(MysqlDatabaseTransactionLog.class);
            }
        });

        BillingService2 billingService3 = injector3.getInstance(BillingService2.class);

        billingService3.charge();
    }
}
